package com.yellowpage.bigdata.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.bigdata.data.UserInfoCount;
import com.yellowpage.bigdata.service.UserInfoCountService;

public class UserInfoCountAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<UserInfoCount> userInfoCountList = new ArrayList<UserInfoCount>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private UserInfoCount userInfoCount;
	private UserInfoCountService userInfoCountService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_id;
		private String query_date;
		private String query_othernum;
		private String query_dxnum;
		private String query_usernum;
		private String end_date;
		
	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.userInfoCount = userInfoCountService.getUserInfoCount(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
	    	    queryMap.put("date", query_date);
	    	    queryMap.put("end_date", end_date);
	    	    	
		resultList = userInfoCountService.queryUserInfoCountByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		userInfoCountService.saveUserInfoCount(userInfoCount);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    	    	    if (userInfoCount.getDate().length() == 0) {
			this.addActionError("** Date 不能为空 !");
		}
			    	    	    	    	    	    	    	    
		this.setValidatorResult("/bigdata/UserInfoCountAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    userInfoCount = userInfoCountService.getUserInfoCount(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    userInfoCountService.updateUserInfoCount(userInfoCount);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    			    if (userInfoCount.getDate().length() == 0) {
			this.addActionError("** Date 不能为空 !");
		}
			    			    			    			    		this.setValidatorResult("/bigdata/UserInfoCountUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.userInfoCountService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲�?删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setUserInfoCount(UserInfoCount userInfoCount) {
		this.userInfoCount = userInfoCount;
	}
	
	public UserInfoCount getUserInfoCount() {
		return userInfoCount;
	}
	 
	 
	 public void setUserInfoCountService(UserInfoCountService userInfoCountService) {
		this.userInfoCountService = userInfoCountService;
	}
	
	public List<UserInfoCount> getUserInfoCountList() {
		return userInfoCountList;
	}

	public void setUserInfoCountList(List<UserInfoCount> userInfoCountList) {
		this.userInfoCountList = userInfoCountList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_id() {
        return this.query_id;
    }
    
    public void setQuery_id(String id){
        this.query_id = id;
    }    

        public String getQuery_date() {
        return this.query_date;
    }
    
    public void setQuery_date(String date){
        this.query_date = date;
    }    

        public String getQuery_othernum() {
        return this.query_othernum;
    }
    
    public void setQuery_othernum(String othernum){
        this.query_othernum = othernum;
    }    

        public String getQuery_dxnum() {
        return this.query_dxnum;
    }
    
    public void setQuery_dxnum(String dxnum){
        this.query_dxnum = dxnum;
    }    

        public String getQuery_usernum() {
        return this.query_usernum;
    }
    
    public void setQuery_usernum(String usernum){
        this.query_usernum = usernum;
    }

	public String getEnd_date() {
		return end_date;
	}

	public void setEnd_date(String end_date) {
		this.end_date = end_date;
	}    

    
	
}
